
@extends('layout.app')

@section('title', '开网预注册')

@section('content')
    @if (count($errors) > 0)
        <div class="card">
            <div class="card-content">
                <div class="card-content-inner">
                    @foreach ($errors->all() as $error)
                        <span style="color: orangered;">{{ $error }}</span><br>
                    @endforeach
                </div>
            </div>
        </div>
    @endif
    <div class="weui_cells weui_cells_form">
        <form action="{{ url('network/submit') }}" method="post">
            <input type="hidden" name="mainForm:code" value="{{ $code }}">
            <input type="hidden" name="mainForm:j_id_jsp_1567340363_55" value="确定">
            <input type="hidden" name="mainForm:submitType" value="add">
            <input type="hidden" name="mainForm_SUBMIT" value="1">
            <input type="hidden" name="mainForm:address" value="">
            <input type="hidden" name="mainForm:userFramedIp" value="">
            <input type="hidden" name="mainForm:userMacAddress" value="">
            <input type="hidden" name="mainForm:userIPv6" value="">
            <input type="hidden" name="autoScroll" value="">
            <input type="hidden" name="javax.faces.ViewState" value="{{ $viewState }}">
            <input type="hidden" name="cookies" value="{{ $sessionId }}">
            <div class="weui_cell">
                <div class="weui_cell_hd"><label class="weui_label">用户姓名</label></div>
                <div class="weui_cell_bd weui_cell_primary">
                    <input name="mainForm:fullName" class="weui_input" type="text">
                </div>
            </div>
            <div class="weui_cell">
                <div class="weui_cell_hd"><label class="weui_label">身份证号</label></div>
                <div class="weui_cell_bd weui_cell_primary">
                    <input name="mainForm:certification" class="weui_input" type="text">
                </div>
            </div>
            <div class="weui_cell">
                <div class="weui_cell_hd"><label class="weui_label">学号/工号</label></div>
                <div class="weui_cell_bd weui_cell_primary">
                    <input name="mainForm:userName" class="weui_input" type="text" placeholder="用作上网账号">
                </div>
            </div>
            <div class="weui_cell">
                <div class="weui_cell_hd"><label class="weui_label">账号密码</label></div>
                <div class="weui_cell_bd weui_cell_primary">
                    <input name="mainForm:userPasswd" class="weui_input" type="text" placeholder="设置上网密码">
                </div>
            </div>
            <div class="weui_cell">
                <div class="weui_cell_hd"><label class="weui_label">电子邮箱</label></div>
                <div class="weui_cell_bd weui_cell_primary">
                    <input name="mainForm:email" class="weui_input" type="text" placeholder="建议填写，用于找回密码">
                </div>
            </div>
            <div class="weui_cell">
                <div class="weui_cell_hd"><label class="weui_label">电话号码</label></div>
                <div class="weui_cell_bd weui_cell_primary">
                    <input name="mainForm:phone" class="weui_input" type="text" placeholder="建议填写，便于网管联系">
                </div>
            </div>
            @foreach($select as $key => $s)
            <div class="weui_cell">
                <div class="weui_cell_hd"><label class="weui_label">{{ $selects[$key] }}</label></div>
                <div class="weui_cell_bd weui_cell_primary">
                    <select class="weui_select" name="{{ 'COLUMN_0' . $name[$key] }}" style="height: 1.41176471em; line-height: 1.41176471; padding-left: 0;">
                        @foreach($s['options'] as $option)
                            <option value="{{ $option }}">{{ $option }}</option>
                        @endforeach
                    </select>
                </div>
            </div>
            @endforeach
            <div class="weui_cell weui_cell_switch">
                <div class="weui_cell_hd weui_cell_primary">记住密码</div>
                <div class="weui_cell_ft">
                    <input class="weui_switch" type="checkbox" name="remember">
                </div>
            </div>
        </form>
    </div>
    <div style="font-size: 13px;color: #8A8A8A; text-align: center; padding-top: 10px;">注：选择“记住密码”后能让你在<br>忘记密码时通过该平台找回密码</div>
    <button id="submit" class="weui_btn weui_btn_primary" style="margin-top: 5px;width: 90%;">提交</button>
    <br>
@endsection



@section('js')
    <script>
        $.ajaxSetup({
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            }
        });

        $("#submit").click(function(){
            if($("input[name='mainForm:fullName']").val() == ''){
                $.toast('请输入姓名', "cancel");
                return;
            }
            if($("input[name='mainForm:certification']").val() == ''){
                $.toast('请输入身份证号', "cancel");
                return;
            }
            if($("input[name='mainForm:userName']").val() == ''){
                $.toast('请输入学号', "cancel");
                return;
            }
            if($("input[name='mainForm:userPasswd']").val() == ''){
                $.toast('请设置密码', "cancel");
                return;
            }
            if($("select[name='COLUMN_01']").val() == ''){
                $.toast('请选择年级', "cancel");
                return;
            }
            if($("select[name='COLUMN_03']").val() == ''){
                $.toast('请选择所属系', "cancel");
                return;
            }
            if($("select[name='COLUMN_02']").val() == ''){
                $.toast('请选择宿舍楼', "cancel");
                return;
            }
            if($("select[name='COLUMN_04']").val() == ''){
                $.toast('请选择楼层', "cancel");
                return;
            }
            if($("select[name='COLUMN_05']").val() == ''){
                $.toast('请选择房号', "cancel");
                return;
            }
            var pattern = /\w[-\w.+]*@([A-Za-z0-9][-A-Za-z0-9]+\.)+[A-Za-z]{2,14}/;
            var emailInput = $("input[name='mainForm:email']");
            if(emailInput.val() != '' && !pattern.test(emailInput.val())){
                $.toast('邮箱格式不正确', "cancel");
                return;
            }
            var patternPhone = /^[\d\-\(\)\+\s]*$/;
            var phoneInput = $("input[name='mainForm:phone']");
            if(phoneInput.val() != '' && !patternPhone.test(phoneInput.val())){
                $.toast('手机号码格式不正确', "cancel");
                return;
            }
            $.showLoading("正在预注册");
            $.ajax({
                type: "POST",
                url: "{{ url('network/submit') }}",
                dataType: "json",
                data: $("form").serialize(),
                success: function(data){
                    $.hideLoading();
                    if(data.msg == 'ok'){
                        $.toast("预注册申请提交成功");
                        if(data.target != ''){
                            setTimeout(function(){
                                window.location.href = data.target;
                            }, 2000);
                        }
                    }else{
                        $.toast(data.msg, "forbidden");
                    }
                }
            })
        });

    </script>
@endsection